//
//  TopicSquareSubListViewController.m
//  BaseProject
//
//  Created by 王洋 on 2020/12/14.
//  Copyright © 2020 王洋. All rights reserved.
//
#import "QuestionAreaCell.h"
#import "QuestionAreaCell.h"
#import "TopicListViewController.h"

#import "TopicSquareSubListViewController.h"

@interface TopicSquareSubListViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableview;

@end

@implementation TopicSquareSubListViewController

- (instancetype)initWith:(NSMutableArray <ProClassificationModel *>*)dataArray {

    self = [super init];
    if (self) {

        self.dataArray = @[].mutableCopy;
        self.dataArray = dataArray;
        
    }
    
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    [self initView];
}

- (void)initView {
    
    [self.view addSubview:self.tableview];
    
    [self.tableview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
    }];
    
    [self.tableview reloadData];
}

#pragma mark UITableviewDelegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
//    return self.dataArray.count;
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 50;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    QuestionAreaCell *cell = [tableView dequeueReusableCellWithIdentifier:@"QuestionAreaCellID"];
    cell.selectionStyle =UITableViewCellSelectionStyleNone;
    [cell.tagIcon setImage:[UIImage imageNamed:@"wodehuati"]];
    cell.mainTitleLab.text = self.dataArray[indexPath.row].parentName;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (self.TopicSquareSubListBlock) {
        self.TopicSquareSubListBlock(self.dataArray[indexPath.row]);
    } else {
        TopicListViewController *vc = [[TopicListViewController alloc] init];
        vc.scId = self.dataArray[indexPath.row].scId;
        [self.navigationController pushViewController:vc animated:YES];
    }
}

- (UITableView *)tableview {
    if (!_tableview) {
        _tableview = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableview.delegate = self;
        _tableview.dataSource = self;
        _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableview.backgroundColor =  UIColorHex(0xffffff);
        
        _tableview.showsHorizontalScrollIndicator = NO;
        _tableview.showsVerticalScrollIndicator = NO;
        
        _tableview.estimatedSectionHeaderHeight = 0;
        _tableview.estimatedSectionFooterHeight = 0;
        _tableview.estimatedRowHeight = 0;
        
        [_tableview registerNib:[UINib nibWithNibName:@"QuestionAreaCell" bundle:nil] forCellReuseIdentifier:@"QuestionAreaCellID"];

    }
    return _tableview;
}

@end
